<?php

namespace app\common\model\Product;

use think\Model;

/**
 * 订单商品类模型
 */
class OrderProduct extends Model
{
  // 设置当前模型对应的完整数据表名称
  protected $table = 'pre_order_product';

  protected $append = [
    'thumb_text',
    'proimg_list'
  ];

  public function getThumbTextAttr($value, $data)
  {
    $url = config('site.url');

    $thumb = !empty($data['thumb']) ? $url . $data['thumb'] : $url . '/assets/img/icon_type.png';

    return $thumb;
  }

  public function getProimgListAttr($value, $data)
  {
    $url = config('site.url');
    $proimg = [];
    if (!empty($data['proimg'])) {

      $proimg =  str_replace('/uploads', $url . '/uploads', $data['proimg']);

      $proimg = explode(',', $proimg);
    }

    return $proimg;
  }
}
